package com.guet.controller.teacher;

import com.guet.VO.StatisticsCountVO;
import com.guet.VO.StatisticsVO;
import com.guet.result.Result;
import com.guet.service.StatisticsService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("teaStatisticsController")
@RequestMapping("teacher/statistics")
@Slf4j
@CrossOrigin
public class StatisticController {
    @Autowired
    private StatisticsService statisticsService;

    @GetMapping("{paperId}")
    public Result<List<StatisticsVO>> getScoreList(@PathVariable int paperId) {
        log.info("paperId:{}", paperId);
        List<StatisticsVO> result = statisticsService.list(paperId);
        return Result.success(result);
    }

    @GetMapping("distribution/{paperId}")
    public Result<List<Integer>> getScoreDistribution(@PathVariable int paperId) {
        log.info("paperId:{}", paperId);
        List<Integer> result = statisticsService.getScoreDistribution(paperId);
        return Result.success(result);
    }

    /**
     * 导出学生成绩
     *
     * @param id
     * @param response
     */
    @GetMapping("export/{id}")
    public void export(@PathVariable int id, HttpServletResponse response) {
        log.info("id:{}", id);
        statisticsService.exportScoreData(response, id);
    }

    /**
     * 每个模块的内容数量
     * @return
     */
    @GetMapping("count")
    public Result<StatisticsCountVO> getStatisticsCount() {
        StatisticsCountVO statisticsCountVO = statisticsService.getStatisticsCount();
        return Result.success(statisticsCountVO);
    }
}
